home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / fortran / libry51.zip / LIBRY4.DOC < prev    next >
Text File  |  1989-11-10  |  6KB  |  98 lines

  1. .pa
  2.                                  MATHEMATICAL
  3.  
  4. These mathematical procedures provide a wide variety  of  functions  that  are
  5. useful for engineering applications.  I began developing this library after my
  6. first experience with SLIM (name changed to protect the guilty) back in  1976.
  7. So  I guess I have them to thank.  If you've ever used SLIM perhaps you've had
  8. a similar experience...
  9.  
  10. Let's  say  you  want  to solve what one would think to be a simple problem of
  11. simultaneous linear equations, and due to some unfortunate turn of events, you
  12. are given SLIM with which to do this.  You are confronted with no less than 60
  13. subroutines from which to choose.  As it turns out,  none  will  do  what  you
  14. want.   Anyway,  you  narrow  it  down  to  the Smith-Jones-Simpson-Wilkerson-
  15. Feinstein-Gidley  method  for  partially  symmetric  matrices   with   strange
  16. sparseness  stored  in  convoluted-compacted  form  (not  to  be confused with
  17. space-saving   form)   and   the   Kleidowitz-Yonkers-Lakeville-Masseykins
  18. modification of the Orwell-Gauss-Newton-Schmeltz algorithm for ill-conditioned
  19. Hilbert matrices  stored  in  space-saving  form  (not  to  be  confused  with
  20. convoluted-compacted  form).  An obvious choice indeed (any fool with 6 Ph.D.s
  21. in math could see that the latter is the preferred  method).   After  numerous
  22. attempts to link your program with all 347 of the necessary SLIM libraries you
  23. are finally ready to run your program.  Of course, it bombs  out  because  you
  24. were reading tuesday afternoon's manual and it's now wednesday morning.  Tough
  25. luck...
  26.  
  27. Actually,  SLIM is so bad that even I can't achieve hyperbole.  Language fails
  28. me.  The above could easily be a random selection from one of the six  volumes
  29. that are supposed to be a "user's guide."
  30.  
  31. Anyway,  I have a completely different philosophy of programming.  I hope that
  32. it works well for you:  if there  is  a  clearly  preferred  method  of  doing
  33. anything, then use it and discard the others.
  34.  
  35. An  excellent example of this is Gauss quadrature.  There are only two methods
  36. of numerical integration that will (at least  in  theory)  converge  given  an
  37. infinite  order:   trapezoidal rule and Gauss quadrature.  Gauss quadrature is
  38. so far superior in accuracy to any  other  method  (e.g.   Newton-Cotes)  it's
  39. practically  incredible.   Therefore,  why have 50 other methods from which to
  40. choose?  An interesting note about this is that, contrary to  some  rumors  10
  41. subdivisions  of  20-point  Gauss  quadrature (200 point evaluation) is not as
  42. accurate as 96-point  Gauss  quadrature  with  less  than  half  the  function
  43. evaluations.
  44.  
  45. Another  example  is  Gauss-Jordan  elimination.   SLIM  has  subroutines that
  46. provide a "high accuracy solution"  (If  Andy  Rooney  understood  this,  he'd
  47. probably  ask,  "Who  would  want  a  low accuracy solution anyway?").  And of
  48. course, there's the iterative improvement type  solutions.   What  they  don't
  49. tell  you  is that the residual must be computed in greater precision than the
  50. matrix is reduced in (say single to double precision) which is  OK;   but  why
  51. not  just  use double precision all the way through?  If you are already using
  52. double precision and that's not good enough for you...  well, you're just  out
  53. of  luck.   If  your matrix is ill- conditioned (as is typically the case with
  54. Vandermondes - that's what you get when you're curve-fitting) about  the  best
  55. thing  you  can use is Gauss-Jordan elimination with full column pivoting.  It
  56. is fast enough and I have used vector emulation throughout.  I have tried  all
  57. sorts of things like QR decompositions, Givens rotations, and a whole bunch of
  58. others;  but it all boils down to the precision of the  math  coprocessor.   I
  59. only  use  one  algorithm for solving full matrices.  I have tested it using a
  60. series of standard Hilbert matrices against SLIM's  "high  accuracy  solution"
  61. and found mine to be both faster and more accurate.
  62.  
  63. One  last  example is the solution of ordinary differential equations.  If you
  64. read numerical mathematics texts, they always give examples of  the  error  in
  65. such-and-such a method as compared to the exact solution.  If you look closely
  66. at the microscopic print in the margin of the legend under the fly  wing  that
  67. got  stuck  on  the  copier, you will probably find the pithy little statement
  68. "exact solution determined using 4-th order Runge-Kutta with 0.0000000001 step
  69. size."  Runge-Kutta  is self-starting (which is a bigger pain in the neck than
  70. you might think if you use a method that isn't), convenient to use, and  works
  71. very  well.   So  why not use it, I ask?  Of course there are certain (unknown
  72. before the fact) cases where other methods  are  much  faster;   but  I  would
  73. rather  spend  less time experimenting with zillions of algorithms and let the
  74. machine sweat a little more.  I've been through it once;  and once is  enough.
  75. Runge-Kutta  is  the one for me.  A word about automatic stepsize control.  It
  76. has been my experience that this takes so long  at  each  step  that  you  are
  77. better  off  to use a smaller step from the start.  I had two such subroutines
  78. that I spent a lot of time on;  but  I  purged  them  one  day  in  a  fit  of
  79. frustration.
  80.  
  81. One  final  note:   WATCH  YOUR  VARIABLE TYPES!  ESPECIALLY DOUBLE PRECISION!
  82. I've seen many a programmer bewildered by a program that crashes because  they
  83. have  passed  "0."  instead  of  "0.D0"  to  a  subroutine  expecting a double
  84. precision value or forgotten to put the "REAL*8" out in front of a function.
  85.  
  86.           REAL*8 FUNCTION DOFX(D)
  87.  
  88. It is really best to use IMPLICIT statements like
  89.  
  90.           IMPLICIT INTEGER*2 (I-N),REAL*8 (A-H,O-Z)
  91.  
  92. than to individually type each variable.   You're  bound  to  miss  one.
  93.  
  94. Another biggy is "O" instead of "0" or vise versa.
  95. .ad LIBRY4A.DOC
  96. .ad LIBRY4B.DOC
  97. .ad LIBRY4C.DOC
  98.